package EurekaProcessor;

import java.io.File;
import java.io.IOException;

import Config.GlobalLog;
import EurekaAnalyzer.WMPageAnalyzer;

public class RawDataAnalyzer extends Thread{
	/*
	private PipelineMgr pMgr;
	*/
	
	private ProcessorMgr pMgr;
	
	private void FSSearch(File file)
	{
		GlobalLog.AddLog("Processing :"+file.getAbsolutePath());
		if(file.isDirectory())
		{
			File[] list = file.listFiles();
			for(File iter:list)
				FSSearch(iter);
		}else
		{
			WMPageAnalyzer analyzer = new WMPageAnalyzer(file);
			if (analyzer.GetURL()==null) {
				return;
			}
			RawDataFromPage rd = new RawDataFromPage();
			rd.board = analyzer.GetBoard();
			rd.ids   = analyzer.GetIDs();
			rd.times = analyzer.GetTimes();
			pMgr.PutNewRawData(rd);
			analyzer = null;
			//analyzer.TheMemeoryProblem();
		}
	}
	
	/*
	public RawDataAnalyzer(PipelineMgr pMgr)
	{
		this.pMgr = pMgr;
	}
	*/
	public RawDataAnalyzer(ProcessorMgr pMgr)
	{
		this.pMgr = pMgr;
	}
	
	public void run()
	{
		Process();
		pMgr.RawDataAnalyzerQuit();
		GlobalLog.AddLog("RawDataAnalyzer Quits...");
	}
	
	
	public void Process()
	{
		File baseDir = new File(pMgr.GetSearchDir());
		if (!baseDir.exists()) {
			GlobalLog.AddLog("Error: Invalid Search Dir :"+pMgr.GetSearchDir()+"occured in RawDataAnalyzer");
			return;
		}
		GlobalLog.AddLog("RawDataAnalyzer Starts...");
		FSSearch(baseDir);
		GlobalLog.AddLog("RawDataAnalyzer Ends...");
	}
	
}
